package com.wjp.dinosaur.config;

import com.wjp.dinosaur.dao.pojo.*;
import com.fasterxml.classmate.TypeResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@EnableSwagger2
@Configuration
public class SwaggerConfig {

    @Autowired
    TypeResolver typeResolver;

    /**
     * 配置docket以配置Swagger具体参数
     */
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.wjp.dinosaur.controller"))
                .build()
                .additionalModels(typeResolver.resolve(User.class));
    }

    /**
     * 配置文档信息
     */
    private ApiInfo apiInfo(){
        Contact contact = new Contact("王建鹏", "地址：null", "2943405106@qq.com");
        return new ApiInfo(
                "会跑的小恐龙",
                "这是个披着小恐龙皮的拳皇",
                "v1.0",
                "地址：null",
                contact,
                "Apach 2.0 许可",
                "",
                new ArrayList<>()
        );
    }
}
